<?php

namespace app\common\model;

use think\Model;

class UserAmount extends Model
{
    /** 新用户注册  建立资金表
     * @param $userId
     * @return UserAmount|Model
     */
    public static function userAmountAdd($userId){
        return self::create([
            'uid' => $userId,
        ]);
    }


    /** 获取用户or商户当前余额  冻结金额 等资金情况
     * @param $where
     * @return array|Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public static function userAmountInfo($where){
        return self::where($where)->find();
    }

    public static function userAmountDec($where,$field,$num){
        return self::where($where)->dec($field,$num)->update();
    }


    public static function userAmountInc($where,$field,$num){
        return self::where($where)->inc($field,$num)->update();
    }
}